﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; 
using Waker.Common;

namespace Waker.SystemSetting
{
    public partial class FormPermissionGroupEdit : Base.FormBasePop
    {
        private DataRow _DrSource;
        public FormPermissionGroupEdit(DataRow dr)
        {
            InitializeComponent();
            _DrSource = dr;
        }

        private void FormPermissionGroupEdit_Load(object sender, EventArgs e)
        {
            this.Text += _DrSource == null ? "添加" : "修改";
            if (_DrSource != null)
            {
                txtGroupName.Text = _DrSource["GroupName"] == DBNull.Value ? string.Empty : _DrSource["GroupName"].ToString();
                txtDescription.Text = _DrSource["Description"] == DBNull.Value ? string.Empty : _DrSource["Description"].ToString();
            }
        }
        protected override void FormSave()
        {
            if (string.IsNullOrEmpty(txtGroupName.Text))
            {
                base.errorPop.SetError(txtGroupName, "权限组名称不能为空");
                return;
            }
            var isOk = new BAL.BAL_SystemSetting().SavePermissionGroup(
                    _DrSource == null ? 0 : Convert.ToInt32(_DrSource["GroupID"])
                    , txtGroupName.Text
                    , txtDescription.Text
                    );
            if (isOk)
            {
                UI.ShowInfo("保存成功");
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                UI.ShowError("保存失败");
            }
        }

    }
}
